<?php if (!isset($_SESSION)) { session_start(); }
include("includes/db.conn.php");
include("includes/conf.class.php");

$hotelId=$_POST['hotelid'];
$room_typeID=$_POST['room_type'];
$room_type=$bsiCore->getRoomtypeId($room_typeID);
$capacity=$bsiCore->getCapacityId($room_typeID);

$roomoffers=$_POST['roomoffers'];
$selected=$_POST['selected'];
$datepicker_form=$_POST['datepicker_form'];
$datepicker_to=$_POST['datepicker_to'];
$currency_id='1';
$total_cost=$_POST['totalcost'];
$totalsaved=$_POST['totalsaved'];
$ip_address= $_SERVER["REMOTE_ADDR"];


$datetime=date('l jS \of F Y h:i:s A');


$roomscount=$bsiCore->getRoomsByRoomType($room_typeID);


	
	$sql=mysql_query("SELECT count(*) as count_room FROM netbiz_booking_details WHERE ('".$datepicker_form."' BETWEEN from_date  AND to_date OR '".$datepicker_to."' BETWEEN from_date AND to_date  OR from_date BETWEEN '".$datepicker_form."' AND '".$datepicker_to."' OR to_date BETWEEN '".$datepicker_form."' AND '".$datepicker_to."' OR from_date='".$datepicker_form."' OR to_date='".$datepicker_to."') and ispaid='n' and room_type_id=".$room_type." and capacity_id=".$capacity);	
	
	$checkcount=mysql_fetch_array($sql);
	
	if($checkcount['count_room']!=$roomscount){									
		
		$selectroom=mysql_query("select room_no from netbiz_room where roomtype_id=".$room_type." and capacity_id=".$capacity."  Order by rand() Limit 1");
		
		$row=mysql_fetch_assoc($sql);
		$room_ID=$row['room_ID'];	
		
		$roomno=mysql_fetch_array($selectroom);
		
		$identifyUser=md5(uniqid(rand(), true));	
		if(!isset($_SESSION['booking']))
		{
		$_SESSION['booking']=$identifyUser;
		}
		
		$insert_temp=mysql_query("insert into netbiz_booking_details(`from_date`,`to_date`,`room_type_id`,`capacity_id`,`hotel_id`,`offer_id`,`extras_id`,`currency_id`,`total_cost`,`saved_price`,`ip_address`,`identity`) values('".$datepicker_form."','".$datepicker_to."','".$room_typeID."','".$capacity."','".$hotelId."','".$roomoffers."','".$selected."','".$currency_id."','".$total_cost."','".$totalsaved."','".$ip_address."','".$_SESSION['booking']."')");
			
		//$updateroom=mysql_query("update netbiz_room set is_block='y',updated_track='".$datetime."' where room_no=".$roomno['room_no']);
		
		echo 'y';
		
	}
	else
	{
		echo 'n';						
	}



?>